home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / day.arc / DAY.PAS next >
Pascal/Delphi Source File  |  1985-08-24  |  6KB  |  223 lines

  1. program DAY(Con);
  2.  
  3.  
  4.    {DAY.PAS #1.00 85-08-17 ORDINAL AND CALENDAR DAY REPORT UTILITY
  5.  
  6.             V01 L00 derived on 85-08-17 by Dennis E. Hamilton, to make
  7.                     it easy to check on any dates handled by DAYLIB.PLB.
  8.                     Some of the basic helper routines were cloned from
  9.                     DAYTST.PAS #3.00 earlier this day.
  10.  
  11.  
  12.     The program DAY provides information about the day number or calendar
  13.     date given as its command-line parameter.  Operating the program with
  14.     no parameters provides an usage summary.
  15.                                                            }
  16.  
  17.  
  18. {$I DAYLIB.PLB } {vintage 3.00 calendar/ordinal-date conversion routines}
  19.  
  20.  
  21. procedure
  22.  
  23.    out2dig(i: integer);
  24.  
  25.    begin {Display the specified value as a 2-digit numeric field}
  26.    if i < 10
  27.    then write(CON, '0', i :1)
  28.    else write(CON,      i :2);
  29.    end {out2dig};
  30.  
  31.  
  32. procedure
  33.  
  34.    OutCalForm(date: calday);
  35.  
  36.    begin {Display the specified value as a yyyy-mm-dd form}
  37.    out2dig(date.year);
  38.    write(CON, '-');
  39.    out2dig(date.mo);
  40.    write(CON, '-');
  41.    out2dig(date.da);
  42.    end {OutCalForm};
  43.  
  44.  
  45. procedure
  46.  
  47.    OutFacts(day: integer);
  48.  
  49.    var date: calday {intermediate value};
  50.  
  51.    begin {Specify qualities of the specified ordinal date}
  52.  
  53.    write(CON, 'day ', day :1, ' is for ');
  54.    case WeekDay(day)
  55.      of 0: write(CON, 'Sunday');
  56.         1: write(CON, 'Monday');
  57.         2: write(CON, 'Tuesday');
  58.         3: write(CON, 'Wednesday');
  59.         4: write(CON, 'Thursday');
  60.         5: write(CON, 'Friday');
  61.         6: write(CON, 'Saturday');
  62.       end;
  63.  
  64.    write(CON, ', ');
  65.    CalDate(date, day);
  66.    OutCalForm(date);
  67.    writeln(CON, '.');
  68.  
  69.    end {OutFacts};
  70.  
  71. procedure
  72.  
  73.    OutItem(v: integer {calendar-entry item} );
  74.  
  75.    begin
  76.    if v = 0
  77.    then write(CON, '   .')
  78.    else write(CON, v :4);
  79.    end {OutItem};
  80.  
  81. const maxw = 42;
  82.              {lowest spot NEVER needed on a rectangular calendar page}
  83.  
  84. var ordnum: integer {ordinal date of the input};
  85.       date: calday {Gregorian date given as input};
  86.          i: integer {working counter};
  87.          k: integer {calendar page column counter};
  88.        cmo: integer {current-month variable for comparison};
  89.        chk: integer {used for error-code determination};
  90.         np: integer {number of parameters presumed};
  91.  
  92.   monthday: array [0 .. maxw] of byte
  93.             {table used to lay out a calendar page};
  94.  
  95.  
  96. BEGIN {DAY}
  97.  
  98. rewrite(CON);
  99. CrtInit;
  100.  
  101. np := ParamCount;
  102. chk := 0;
  103.  
  104. if np = 1
  105. then Val(ParamStr(1), ordnum, chk);
  106.  
  107. if np > 1
  108. then begin
  109.      Val(ParamStr(1), date.year, chk);
  110.      if chk = 0
  111.      then begin
  112.           Val(ParamStr(2), i, chk);
  113.           date.mo := i;
  114.           date.da := 0;
  115.           if (ParamCount > 2) and (chk = 0)
  116.           then begin
  117.                Val(ParamStr(3), i, chk);
  118.                date.da := i;
  119.                end;
  120.           end;
  121.      end;
  122.  
  123. if (chk = 0) and (np = 1)
  124. then CalDate(date, ordnum);
  125.  
  126. if (chk = 0) and (np > 0)
  127. then if BadDate(date)
  128.      then chk := 1;
  129.  
  130. if chk = 0 then ClrScr;
  131. writeln(CON, 'DAY> #1.00 85-08-17 ORDINAL-GREGORIAN DATE-CHECK UTILITY');
  132. writeln(CON, '     CompuServe Forum edition by Dennis E. Hamilton');
  133. writeln(CON);
  134.  
  135. if chk <> 0
  136. then begin
  137.      write(CON, '     +++ Invalid Parameter Value: ');
  138.      for i := 1 to np
  139.       do write(CON, ParamStr(i), ' ');
  140.      writeln(CON, #7);
  141.      writeln(CON, #7);
  142.      end;
  143.  
  144. if np = 0 then chk := 1;
  145. if chk <> 0
  146. then begin
  147.      writeln(CON, '     A0>DAY ordnum             reports facts about the');
  148.      writeln(CON, '                               ordnum parameter, taken');
  149.      writeln(CON, '                               as number of days since');
  150.      writeln(CON, '                               1977 12 31.');
  151.      writeln(CON);
  152.      writeln(CON, '     A0>DAY year mo da         reports facts about the');
  153.      writeln(CON, '                               Gregorian date given in');
  154.      writeln(CON, '                               the range 1888 04 13 to');
  155.      writeln(CON, '                               2067 09 17.');
  156.      writeln(CON);
  157.      end;
  158.  
  159. if chk = 0
  160. then begin
  161.      ordnum := since77(date);
  162.      writeln(CON);
  163.      write  (CON, '     ');
  164.      OutFacts(ordnum);
  165.      writeln(CON);
  166.      writeln(CON);
  167.      case date.mo
  168.        of 1: write(CON, '                 January');
  169.           2: write(CON, '                February');
  170.           3: write(CON, '                   March');
  171.           4: write(CON, '                   April');
  172.           5: write(CON, '                     May');
  173.           6: write(CON, '                    June');
  174.           7: write(CON, '                    July');
  175.           8: write(CON, '                  August');
  176.           9: write(CON, '               September');
  177.          10: write(CON, '                 October');
  178.          11: write(CON, '                November');
  179.          12: write(CON, '                December');
  180.         end;
  181.  
  182.      writeln(CON, date.year :6);
  183.  
  184.      writeln(CON);
  185.  
  186.      writeln      (CON, '          Su  Mo  Tu  We  Th  Fr  Sa');
  187.      writeln(CON);
  188.  
  189.      for i := 0 to maxw do monthday[i] := 0;
  190.         {clearing all calendar buckets to zero for starters};
  191.  
  192.      date.da := 1;
  193.      cmo := date.mo;
  194.      ordnum := since77(date);
  195.      i := weekday(ordnum);
  196.         {setting up for first of month in monthday list};
  197.  
  198.      repeat
  199.         monthday[i] := date.da;
  200.         ordnum := succ(ordnum);
  201.         i := succ(i);
  202.         CalDate(date, ordnum);
  203.         until date.mo <> cmo;
  204.  
  205.      i := 0;
  206.      repeat
  207.         write(CON, '        ');
  208.         for k := 1 to 7
  209.          do begin
  210.             OutItem(monthday[i]);
  211.             i := succ(i);
  212.             end;
  213.         writeln(CON);
  214.         until monthday[i] = 0;
  215.  
  216.      writeln(CON);
  217.      end;
  218.  
  219. CrtExit;
  220. close(CON);
  221.  
  222. END. {DAY}
  223.